package me.zhengjie.modules.quartz.task;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.business.domain.Msg;
import me.zhengjie.business.domain.Zhsq;
import me.zhengjie.business.repository.GsRepository;
import me.zhengjie.business.repository.ZhsqRepository;
import me.zhengjie.inter.service.MpMsgService;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.UserDto;
import me.zhengjie.utils.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * 查询昨天待遇过期的照护申请，并更改状态
 * @author xiahongbo
 * @date 2022-11-19
 */
@Slf4j
@Async
@Component
public class DyzzTask {

    @Autowired
    private ZhsqRepository zhsqRepository;


    @Transactional
    public void dyzz() {
        // 当前时间
        String datetime = DateUtil.format(DateUtil.date(), DatePattern.NORM_DATETIME_MS_PATTERN);
        log.info("查询昨天待遇过期的照护申请，并更改状态 {}" + datetime);
        String ids = zhsqRepository.queryGqdyzhsq();
        String[] idsArray = ids.split(",");
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < idsArray.length; i++) {
            Long zhid = Long.parseLong(idsArray[i]);
            list.add(zhid);
        }
        zhsqRepository.batchUpdateZhzt("90", list);
    }
}
